<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;

use App\Http\Util\HomeTool;
use App\Utils\Result;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;

class NormalController extends Controller
{
    /**
     * 获取信息
     */
    public function detail(Request $request){
        try{
            $data_key = "SET_WEB_NORMAL_WEN";
            $data = json_decode(Redis::get($data_key),true);
            if(!$data){
                $data = '';
            }
            return response()->json(['code' => 200,'data'=>$data]);
        }catch(\Exception $e){
            echo $e->getMessage();
        }
    }



    /**修改
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function create(Request $request)
    {;
        $check_roles = HomeTool::checkRoles(119,'edit');
        if(!$check_roles){
            return response()->json(['code' => 1001, 'msg' => '暂无此操作权限']);
        }
        $key = "SET_WEB_NORMAL_WEN";
        $data = $request->post();
        Redis::set($key,json_encode($data));
        return response()->json(['code' => 200, 'msg' => '更改成功']);
    }

    public function checkRecord(Request $request){
            $mac= $request->input('mac');
            $check = \App\Models\Device::where('mac',$mac)->first();
            if($check){
                $data['is_check'] = 1;
                $data['sn'] = $check->sn;
            }else{
                $data['is_check'] = 0;
                $data['sn'] = '';
            }
            return Result::success($data);
    }
}
